package hr_project.hr.biz.Salary;

import java.beans.IntrospectionException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import hr_project.hr.dao.ISalaryDao;
import hr_project.hr.entity.Emp;
import hr_project.hr.entity.Salary;
import hr_project.hr.entity.Salary_standerd_info;
import hr_project.hr.util.ExcelBean;
import hr_project.hr.util.ExcelUtil;
import hr_project.hr.util.QuerySalary;
import hr_project.hr.util.pagebean;

/**
 * @author 冯亚倩
 *  薪资标准实现类
 * */


@Service
public class SalaryBizImp implements ISalaryBiz {

	@Autowired
	private ISalaryDao dao;
	
	
	public ISalaryDao getDao() {
		return dao;
	}
	public void setDao(ISalaryDao dao) {
		this.dao = dao;
	}

	
	@Override
	public void modSalary(Salary ss,List<Salary_standerd_info> slist) {
		// TODO Auto-generated method stub
		dao.modSalary(ss, slist);
	}


	@Override
	public List<Salary> getAll() {
		// TODO Auto-generated method stub
		return dao.getAll();
	}



	@Override
	public pagebean getPage(QuerySalary qs, int page) {
		// TODO Auto-generated method stub
		pagebean bean=new pagebean();
		bean.setCurrpage(page);
		bean.setPageSize(5);
		bean.setList(dao.getPage(qs, page, bean.getPageSize()));
		bean.setTotalRow(dao.getCount(qs));
		return bean;
	}



	@Override
	public Salary getById(long said) {
		// TODO Auto-generated method stub
		return dao.getById(said);
	}
	@Override
	public void cancleSalary(Salary ss, List<Salary_standerd_info> slist) {
		// TODO Auto-generated method stub
		dao.cancleSalary(ss, slist);
	}
	@Override
	public void update_sal(Salary ss) {
		// TODO Auto-generated method stub
		dao.update_sal(ss);
	}
	@Override
	public pagebean getPage1(QuerySalary qs, int page,long man_id) {
		// TODO Auto-generated method stub
		pagebean bean=new pagebean();
		bean.setCurrpage(page);
		bean.setPageSize(5);
		bean.setList(dao.getPage1(qs, page, bean.getPageSize(), man_id));
		bean.setTotalRow(dao.getCount1(qs, man_id));
		return bean;
	}
	@Override
	public pagebean getPage2(QuerySalary qs, int page) {
		// TODO Auto-generated method stub
		pagebean bean=new pagebean();
		bean.setCurrpage(page);
		bean.setPageSize(5);
		bean.setList(dao.getPage2(qs, page, bean.getPageSize()));
		bean.setTotalRow(dao.getCount2(qs, page));
		return bean;
	}
	@Override
	public pagebean getPage_ff(QuerySalary qs, int page) {
		// TODO Auto-generated method stub
		pagebean bean=new pagebean();
		bean.setCurrpage(page);
		bean.setPageSize(5);
		bean.setList(dao.getPage_ff(qs, page, bean.getPageSize()));
		bean.setTotalRow(dao.getCount_ff(qs));
		return bean;
	}
	@Override
	public pagebean getPage_del(QuerySalary qs, int page) {
		// TODO Auto-generated method stub
		pagebean bean=new pagebean();
		bean.setCurrpage(page);
		bean.setPageSize(5);
		bean.setList(dao.getPage_del(qs, page, bean.getPageSize()));
		bean.setTotalRow(dao.getCount_del(qs));
		return bean;
	}
	
	@Override
	public XSSFWorkbook emexcel() {
		// TODO Auto-generated method stub
		  //在dao层中获取数据
		List<Map<String,Object>> list = dao.findAll();
		 //设置一个集合用来存放每一行的数据也就是一个ExcelBean对象
		 List<ExcelBean> excel = new ArrayList<>();
		 //行号，对应一个对象
		 Map<Integer,List<ExcelBean>> map = new LinkedHashMap<>();
		//设置标题栏
		 excel.add(new ExcelBean("员工编号","eid",0));
		 excel.add(new ExcelBean("员工姓名","ename",0));
		 excel.add(new ExcelBean("总工资","sum",0));
		 excel.add(new ExcelBean("基本工资","base", 0));
		 excel.add(new ExcelBean("创建时间","creattime",0));
		 excel.add(new ExcelBean("薪资标准","said", 0));
		 excel.add(new ExcelBean("部门名称","dname",0));
		 excel.add(new ExcelBean("部门编号","did",0));
		 map.put(0,excel);
		 String sheetName = "员工薪资表";
		 
		//调用ExcelUtil方法
		 XSSFWorkbook xssfWorkbook=null;
		 
		 try {
			 
			xssfWorkbook = ExcelUtil.createExcelFile(Emp.class, list, map, sheetName);
		    
		 
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IntrospectionException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		 
		 return xssfWorkbook;
	}





}
